<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php $this->load->view('common/head');?>
<body class="no-skin">
<?php $this->load->view('common/header');?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar');?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs');?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set');?>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal" action="<?php echo site_url(X_URL.'project/update');?>" method="post">
						<?php echo csrf_hidden();?>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 项目名 </label>
                                <div class="col-sm-9">
                                    <input type="text" class="rcol-xs-10 col-sm-5" name="project_name" id="project_name" value="<?php if(isset($project)){ echo $project["project_name"];}?>">
                                    <input type="hidden" name="project_id" value="<?php if(isset($project)){ echo $project["project_id"];}?>">
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group row">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 标签 </label>
                                <div class="col-sm-9" style="padding-left: 0px;">
                                    <?php if($tags){
                                        foreach ($tags as $key=>$val){?>
                                    <label class="col-xs-2" style="width:100px;">
                                        <input name="project_tag[]" id="project_tag" class="ace ace-checkbox-2 children" <?php if (!empty($project) && in_array($key, $project['project_tag'])) {
                                        echo 'checked="checked"';}; ?> type="checkbox" value="<?php echo $key;?>"/>
                                    <span class="lbl"><?php echo $val;?> </span>
                                    </label>
                                      <?php  }
                                    }?>

                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 类型 </label>
                                <div class="col-sm-9" style="padding-left: 0px;">
                                    <?php if($types){
                                        foreach ($types as $key=>$val){?>
                                            <label class="col-xs-2" style="width:100px;">
                                                <input id="project_type" name="project_type[]" class="ace ace-checkbox-2 children" <?php if (!empty($project) && in_array($key, $project['project_type'])) {
                                                    echo 'checked="checked"';}; ?> type="checkbox" value="<?php echo $key;?>"/>
                                                <span class="lbl"><?php echo $val;?> </span>
                                            </label>
                                        <?php  }
                                    }?>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 参与人员 </label>
                                <div class="col-sm-9" style="padding-left: 0px;">
                                    <?php if($use){
                                        foreach ($use as $key=>$val){?>
                                    <div class="col-sm-7" style="padding-left: 0px;">
                                        <label class="col-xs-9">
                                                    <input  name="project_user_id[]" class="ace ace-checkbox-2 children" <?php if (!empty($project) && in_array($val['user_id'], $project['project_user_id'])) {
                                                        echo 'checked="checked"';}; ?> type="checkbox" value="<?php echo $val['user_id']?>" onclick="check(this,'<?php echo $val['user_id']?>');"/>
                                                    <span class="lbl col-sm-3" style="height: 40px;padding-left: 0px;"><?php echo $val['user_uname'];?> &nbsp;&nbsp;&nbsp;</span>
                                            <span id="input_box<?php echo $val['user_id']?>"><span id="divs<?php echo $val['user_id']?>"><?php if(isset($val['into_num']) && in_array($val['user_id'], $project['project_user_id'])){?> <input type='text' id="div<?php echo $val['user_id']?>" style='width:150px' placeholder='提成数' name='into_num[]' value='<?php echo $val['into_num']; ?>'> <?php }?></span>
                                        </label>
                                    </div>
                                        <?php  }?>
                                   <?php }?>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2">客户名称 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="project_customer" id="project_customer" placeholder="客户名称"
                                           class="col-xs-10 col-sm-5" value="<?php if(!empty($project['project_customer'])){  echo $project['project_customer'];}?>">
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-6"> 客户联系电话 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="project_customer_tel" id="project_customer_tel" placeholder="电话号码"
                                           class="col-xs-10 col-sm-5" value="<?php if(!empty($project['project_customer_tel'])){  echo $project['project_customer_tel'];}?>">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-7"> 项目开始时间 </label>
                                <div class="input-group col-sm-3" style="padding-left: 15px;">
                                    <input type="text" class="form-control input-mask-product" name='project_start_time'  id="test2" placeholder="<?php if(!empty($project['project_start_time'])){  echo $project['project_start_time'];}?>" placeholder="yyyyMM">
                                    <span class="input-group-addon">
                                        <i class="ace-icon fa fa-calendar bigger-100 "></i>
                                    </span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-7"> 项目结束时间 </label>
                                <div class="input-group col-sm-3" style="padding-left: 15px;">
                                    <input type="text" class="form-control input-mask-product" name='project_end_time'  id="test1" placeholder="<?php if(!empty($project['project_end_time'])){  echo $project['project_end_time'];}?>" placeholder="yyyyMM">
                                    <span class="input-group-addon">
                                        <i class="ace-icon fa fa-calendar bigger-100 "></i>
                                    </span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-7"> 总价格 </label>
                                <div class="input-group col-sm-3" style="padding-left: 15px;">
                                    <input class="form-control input-mask-product" type="text" name="project_total_money" id="project_total_money" placeholder="总价格" class="col-xs-10 col-sm-5" value="<?php if(!empty($project['project_total_money'])){  echo $project['project_total_money'];}?>">
                                    <span class="input-group-addon">
                                        <i class="ace-icon fa fa-rmb bigger-100 "></i>
                                    </span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-7"> 已收款 </label>
                                <div class="input-group col-sm-3" style="padding-left: 15px;">
                                    <input class="form-control input-mask-product" type="text" name="project_get_money" id="project_get_money" placeholder="已收款" class="col-xs-10 col-sm-5" value="<?php if(!empty($project['project_get_money'])){  echo $project['project_get_money'];}?>" <?php if(!empty($project['project_get_money'])){ echo "disabled='disabled'";}?>>
                                    <span class="input-group-addon">
                                        <i class="ace-icon fa fa-rmb bigger-100 "></i>
                                    </span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-7"> 派发价 </label>
                                <div class="input-group col-sm-3" style="padding-left: 15px;">
                                    <input class="form-control input-mask-product" type="text" name="project_money" id="project_money" placeholder="派发价" class="col-xs-10 col-sm-5" value="<?php if(!empty($project['project_money'])){  echo $project['project_money'];}?>">
                                    <span class="input-group-addon">
                                        <i class="ace-icon fa fa-rmb bigger-100 "></i>
                                    </span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 项目进度 </label>
                                <div class="col-sm-9">
                                    <select id="project_status" name="project_status" class="multiselect">
                                        <option value="0" <?php if(!empty($project['project_status']) && $project['project_status']==0) echo "selected='selected'"?>>未开始</option>
                                        <option value="1" <?php if(!empty($project['project_status']) && $project['project_status']==1) echo "selected='selected'"?>>制作中</option>
                                        <option value="2" <?php if(!empty($project['project_status']) && $project['project_status']==2) echo "selected='selected'"?>>测试中</option>
                                        <option value="3" <?php if(!empty($project['project_status']) && $project['project_status']==3) echo "selected='selected'"?>>已完成</option>
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info" type="submit">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>
                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </form>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <?php $this->load->view('common/footer');?>
</div><!-- /.main-container -->

<?php $this->load->view('common/footerjs');?>
<?php echo admin_js_url('laydate');?>
<!-- inline scripts related to this page -->
<script type="text/javascript">

    function check (chk,user_id) {
        var box = document.getElementById('input_box'+user_id);
        var ids = 'divs'+user_id;
        if (chk.checked) {
            box.innerHTML="<span id='divs"+user_id+"'><input type='text' style='width:150px' placeholder='所填总和不能大于1' name='into_num[]' value=''></span>";
        }else {
            box.removeChild(document.getElementById('divs'+user_id));
        }
    }
    $(function () {
        lay('#version').html('-v'+ laydate.v);
        laydate.render({
            elem: '#test1' //指定元素
        });
        laydate.render({
            elem: '#test2' //指定元素
        });
        $(".btn-info").click(function () {
            var project_name = $("#project_name").val();
            var project_customer = $("#project_customer").val();
            var project_total_money = $("#project_total_money").val();
            var project_get_money = $("#project_get_money").val();
            var project_money = $("#project_money").val();
            var project_customer_tel = $("#project_customer_tel").val();
            if(project_name== ''){
                bootbox.dialog({
                    title:"系统提示",
                    message: "项目名称必须填写",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            var tag = document.getElementsByName("project_tag[]");
            var tagNum = 0;
            for (var i = 0; i < tag.length; i++) {
                if (tag[i].checked) {
                    tagNum++;
                }
            }
            if (tagNum == 0) {
                bootbox.dialog({
                    title:"系统提示",
                    message: "标签必须选择",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            var cbs = document.getElementsByName("project_type[]");
            var typeNum = 0;
            for (var i = 0; i < cbs.length; i++) {
                if (cbs[i].checked) {
                    typeNum++;
                }
            }
            if (typeNum == 0) {
                bootbox.dialog({
                    title:"系统提示",
                    message: "类型必须选择一个",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            var users = document.getElementsByName("project_user_id[]");
            var userNum = 0;
            for (var i = 0; i < users.length; i++) {
                if (users[i].checked) {
                    userNum++;
                }
            }
            if (userNum == 0) {
                bootbox.dialog({
                    title:"系统提示",
                    message: "参与成员必须填写",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if(project_customer== ''){
                bootbox.dialog({
                    title:"系统提示",
                    message: "客户名称必须填写",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if(project_customer_tel== ''){
                bootbox.dialog({
                    title:"系统提示",
                    message: "客户电话需要填写",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if(project_total_money== ''){
                bootbox.dialog({
                    title:"系统提示",
                    message: "总金额必须填写",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if(project_get_money== ''){
                bootbox.dialog({
                    title:"系统提示",
                    message: "收款金额必须填写",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (parseFloat(project_get_money) > parseFloat(project_total_money)) {
                bootbox.dialog({
                    title:"系统提示",
                    message: "收款金额不能大于总收款金额",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if(project_money== ''){
                bootbox.dialog({
                    title:"系统提示",
                    message: "派发价必须填写",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            if (parseFloat(project_money) > parseFloat(project_total_money)) {
                bootbox.dialog({
                    title:"系统提示",
                    message: "派发价不能大于总价格",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }

            $("#form").submit();
        })
    })
</script>
</body>
</html>
